package com.bj.disc.service;

import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class WebSocketService extends Service {

    Handler handler=new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            if(!WebSocketInstance.getInstance().send("ping")){
                WebSocketInstance.getInstance().connect(WebSocketInstance.getInstance().getLastSendContent());
            }
            handler.sendEmptyMessageDelayed(0,15*1000);
        }
    };
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        WebSocketInstance.getInstance().connect();
       // handler.sendEmptyMessageDelayed(0,15*1000);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        handler.removeCallbacksAndMessages(null);
    }
}
